<template>
    <div id="bottomRightChart" style="width:6.5rem;"></div>
</template>

<script>
import echartMixins from "@/utils/resizeMixins";

export default {
  data() {
    return {
      chart: null,
      "refreshData": null,
    };
  },
  mixins: [echartMixins],
  created() {
  },
  mounted() {
    this.draw();
    this.refreshData = window.setInterval(
        () => {
          setTimeout(this.draw, 0)
        }, 1000 * 60 * 60 * 4)
  },
  methods: {
    async draw() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = this.$echarts.init(document.getElementById("bottomRightChart"));
      const resData = await this.$http.get("/opc/abnormal/pro_line");
      let category = []
      let barData = []
      if (resData.data.code === 0) {
        category = resData.data.data.lineList
        barData = resData.data.data.list
      }
      let option = {
        title: {
          text: "",
          x: "center",
          y: 0,
          textStyle: {
            color: "#B4B4B4",
            fontSize: 16,
            fontWeight: "normal"
          }
        },
        tooltip: {
          trigger: "axis",
          backgroundColor: "rgba(255,255,255,0.1)",
          axisPointer: {
            type: "shadow",
            label: {
              show: true,
              backgroundColor: "#7B7DDC"
            }
          }
        },
        legend: {
          data: ["异常消耗数"],
          textStyle: {
            color: "#B4B4B4"
          },
          top: "1%"
        },
        grid: {
          x: "8%",
          width: "80%",
          y: "16%"
        },
        xAxis: {
          data: category,
          axisLine: {
            lineStyle: {
              color: "#B4B4B4"
            }
          },
          axisTick: {
            show: false
          }
        },
        yAxis: [
          {
            splitLine: {show: false},
            axisLine: {
              lineStyle: {
                color: "#B4B4B4"
              }
            },
            axisLabel: {
              formatter: "{value} "
            },
            minInterval: 1,
          }
        ],
        series: [
          {
            name: "异常消耗数",
            type: "bar",
            barWidth: 35,
            itemStyle: {
              normal: {
                barBorderRadius: 5,
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {offset: 0, color: "#956FD4"},
                  {offset: 1, color: "#3EACE5"}
                ])
              }
            },
            data: barData
          }
        ]
      };
      this.chart.setOption(option);
    }
  },
  destroyed() {
    window.onresize = null;
    clearInterval(this.refreshData);
    this.refreshData = null;
  }
};
</script>

<style lang="scss" scoped>
</style>